using Digitalmes.Application.Mes.Equipments.StandardParts;
using Digitalmes.Application.Mes.Equipments.StandardParts.Commands;
using Digitalmes.Application.Mes.Equipments.StandardParts.Queries;

namespace Digitalmes.WebApi.Endpoints.Mes.Equipments;

/// <summary>
/// 设备点检标件终结点。
/// </summary>
public sealed class StandardPartsEndpoint : EndpointGroupBase
{
    public override void Map(WebApplication app)
    {
        app.MapGroup(this, "mes/equipment", "standardParts")
            .RequireAuthorization()
            .MapGet(GetInspectionStandardPartsPagedListAsync, "list-page")
            .MapPost(CreateInspectionStandardPartsAsync)
            .MapPut(UpdateInspectionStandardPartsAsync, "{id}")
            .MapDelete(DeleteInspectionStandardPartsAsync, "{id}");
    }

    [EndpointDescription("分页查询设备点检标件")]
    public async Task<IApiResult> GetInspectionStandardPartsPagedListAsync(ISender sender, [AsParameters] GetStandardPartsListWithPagedQuery query)
    {
        var result = await sender.Send(query);
        return result.ToApiResult();
    }

    [EndpointDescription("创建设备点检标件")]
    public async Task<IApiResult> CreateInspectionStandardPartsAsync(ISender sender, EquipInspectionStandardPartsDto dto)
    {
        var result = await sender.Send(new CreateStandardPartsCommand(dto));
        return result.ToApiResult();
    }

    [EndpointDescription("更新设备点检标件")]
    public async Task<IApiResult> UpdateInspectionStandardPartsAsync(ISender sender, long id, EquipInspectionStandardPartsDto dto)
    {
        var result = await sender.Send(new UpdateStandardPartsCommand(id, dto));
        return result.ToApiResult();
    }

    [EndpointDescription("删除设备点检标件")]
    public async Task<IApiResult> DeleteInspectionStandardPartsAsync(ISender sender, long id)
    {
        var result = await sender.Send(new DeleteStandardPartsCommand(id));
        return result.ToApiResult();
    }
}
